

#ifndef MW_DB_RESULT_SET_H_
#define MW_DB_RESULT_SET_H_

#include <winsock2.h>
#include <mysql.h>
#include <string>
#include "../Lib_Base/inc/Types.h"

namespace db
{

class ResultSet
{
public:
	// mysql_res should be fetch by mysql_store_result, not mysql_use_result
	// and should never be NULL.
	ResultSet(MYSQL_RES* mysql_res, MYSQL* mysql);
	~ResultSet();

	void reset();
	bool next();
	uint64 num_rows() { return num_rows_; }
	uint64 affected_rows() { return affected_rows_; }
	uint64 inserted_id() { return inserted_id_; }
	int	getCurLength(size_t column);

	bool isNull(size_t column);
	bool getBoolean(size_t column);
	int32 getInt32(size_t column);
	uint32 getUint32(size_t column);
	int64 getInt64(size_t column);
	uint64 getUint64(size_t column);
	float getFloat(size_t column);
	double getDouble(size_t column);
	std::string getString(size_t column);
	bool getBinary(size_t column, void* pBuff, unsigned long nBuffLen);
	
private:
	ResultSet(const ResultSet&);
	ResultSet& operator=(const ResultSet&);

	bool isValid(size_t column);

	size_t num_columns_;
	uint64 num_rows_;
	int cursor_;
	MYSQL_RES* mysql_res_;
	MYSQL_ROW cur_row_;
	unsigned long* cur_lengths_;
	uint64 affected_rows_;
	uint64 inserted_id_;
};

} // end namespace db

#endif // MW_DB_RESULT_SET_H_